Skip to content

PostgreSQL: Parse ROUTINE and ALL PROCEDURES | ROUTINES IN SCHEMA grant targets - #2761

Merged
LucaCappelletti94 merged 2 commits into
mainfrom
upstream/grant-routine
Oct 30, 2026
Merged

LucaCappelletti94 merged 2 commits into
mainfrom
upstream/grant-routine

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

PostgreSQL's GRANT and REVOKE take ON ROUTINE with the same signature list as ON FUNCTION and ON PROCEDURE, and cover a whole schema with ON ALL PROCEDURES IN SCHEMA and ON ALL ROUTINES IN SCHEMA (https://www.postgresql.org/docs/current/sql-grant.html). None of the three parsed. GRANT EXECUTE ON ROUTINE f(int) TO bob failed with Expected: TO, found: f, and GRANT EXECUTE ON ALL ROUTINES IN SCHEMA s TO bob with Expected: TO, found: ROUTINES.

GrantObjects gains Routines, AllProceduresInSchema and AllRoutinesInSchema, next to the Functions and Procedures variants from #2727. A routine can be a function or a procedure, so each form keeps its own variant and prints back as written.

@codecov-commenter

codecov-commenter commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.59%. Comparing base (06c0468) to head (88c587b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2761      +/-   ##
==========================================
+ Coverage   82.58%   82.59%   +0.01%     
==========================================
  Files          42       42              
  Lines       35565    35597      +32     
  Branches    35565    35597      +32     
==========================================
+ Hits        29371    29403      +32     
  Misses       2660     2660              
  Partials     3534     3534              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/parser/mod.rs Outdated
Some(GrantObjects::Procedures(
self.parse_comma_separated(Parser::parse_function_desc)?,
))
} else if self.parse_keyword(Keyword::ROUTINE) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks a table named routine: GRANT SELECT ON TABLE routine TO r parses, but Tables prints without TABLE, so the output GRANT SELECT ON routine TO r no longer re-parses (Expected: TO, found: r). Guarding on the next token being a word other than TO/FROM before consuming ROUTINE avoids it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think tables named function, procedure and sequence would also break here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ROUTINE is now only read as the object type when the next token is not TO, FROM, , or ., which is how PostgreSQL itself tells a table named routine from a routine.

Tables named function, procedure and sequence already failed this way on main, and so did schema, database, view and the other object-type keywords. The same check now guards all of them, so GRANT SELECT ON function TO r and the rest parse as tables and ON TABLE function round-trips.

@sabir-akhadov-localstack sabir-akhadov-localstack left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@LucaCappelletti94

Copy link
Copy Markdown
Contributor Author

Thanks @sabir-akhadov-localstack for the review! I will be merging this one now.

cc @alamb

@LucaCappelletti94
LucaCappelletti94 added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit c6cec56 Oct 30, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants